package com.lixunhuan.handacount.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lixunhuan.handacount.common.ResultInfo;
import com.lixunhuan.handacount.db.bean.Kind;
import com.lixunhuan.handacount.service.IKindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lixunhuan
 * @since 2021-03-19
 */
@RestController
@RequestMapping("/kind")
public class KindController {

    @Autowired
    private IKindService kindService;
    @RequestMapping("select")
    public ResultInfo selectKinds(@RequestParam("type") Integer type){
        return new ResultInfo(ResultInfo.Status.SUCCESS).result(
              kindService.list(new QueryWrapper<Kind>().eq("type",type).orderByAsc("id"))
        );
    }

    @RequestMapping("delete")
    public ResultInfo delete(@RequestParam("kind_id")Integer kindId){
        kindService.removeById(kindId);
        return new ResultInfo(ResultInfo.Status.SUCCESS).message("删除标签成功");
    }

    @RequestMapping("add")
    public ResultInfo add(@RequestParam("type") Integer type,
                          @RequestParam("desc") String desc,
                          @RequestParam("iconstr")String iconstr){
        Kind kind = new Kind();
        kind.setType(type);
        kind.setDescstr(desc);
        kind.setIconstr(iconstr);
        kindService.save(kind);
        return new ResultInfo(ResultInfo.Status.SUCCESS).message("标签添加成功");
    }
}
